package 笔试真题;

public class Mihayou2 {
    public static void main(String[] args) {
        Mihayou2 mihayou2 = new Mihayou2();
        mihayou2.computeN(11);

    }
    public int computeN (int maxValue) {
        // write code here
        for (int i = 0; i < 1000000; i++) {
            if(i==getNum(String.valueOf(i))){
                System.out.println(i+":"+getNum(String.valueOf(i)));
            }
        }
        return 0;
    }

    public int getNum(String s){
        if(s.length()==1) return s.equals("0")?0:1;
        int sum =0;
        int len = s.length();
        int p = s.charAt(0)-'0';
        sum += p * Math.pow(10,len-2) * (len-1) ;
        if(p>1){
            sum+= Math.pow(10,len-1);
        }else if(p==1){
            sum += Integer.parseInt(s.substring(1));
        }
        return sum + getNum(s.substring(1));
    }
}
